//
//  YBCloudComputerBasicFuncCell.swift
//  Moonlight
//
//  Created by Penlon Kim on 2023/6/8.
//  Copyright © 2023 Moonlight Game Streaming Project. All rights reserved.
//

import UIKit
import SnapKit
import SwifterSwift

class YBCloudComputerBasicFuncCell: UITableViewCell {
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.selectionStyle = .none
        self.backgroundColor = .lightWhiteDark33
        contentView.backgroundColor = .lightWhiteDark33
        
        contentView.addSubviews([imgView, kTitleLabel, desLabel, lineView])
        
        imgView.snp.makeConstraints { make in
            make.top.equalTo(10)
            make.left.equalTo(20)
            make.size.equalTo(22)
        }
        
        kTitleLabel.snp.makeConstraints { make in
            make.centerY.equalTo(imgView)
            make.left.equalTo(imgView.snp.right).offset(6)
            make.height.equalTo(20)
        }
        
        desLabel.snp.makeConstraints { make in
            make.top.equalTo(imgView.snp.bottom)
            make.left.equalTo(kTitleLabel.snp.left)
            make.right.equalTo(-20)
        }
        
        lineView.snp.makeConstraints { make in
            make.top.equalTo(desLabel.snp.bottom).offset(10)
            make.left.equalTo(20)
            make.right.equalTo(-26)
            make.height.equalTo(1)
            make.bottom.equalToSuperview()
        }
        
    }
    
    /// 重写frame
    override var frame: CGRect {
        get { return super.frame }
        set {
            var frame = newValue
            frame.origin.x += 10
            frame.size.width -= 2*10
            super.frame = frame
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - lazy
    private lazy var imgView: UIImageView = {
        let iv = UIImageView()
        iv.bk_addCornerBorder(radius: 11, borderWidth: 0.1, borderColor: .clear)
        iv.contentMode = .scaleAspectFill
        iv.clipsToBounds = true
        return iv
    }()
    
    private lazy var kTitleLabel = self.bk_addLabel(font: .systemFont(ofSize: 14), bgColor: .clear, textColor: .lightBlack51DarkLight230)
    
    private lazy var desLabel = self.bk_addLabel(font: .systemFont(ofSize: 12), bgColor: .clear, textColor: ColorDef.gray102)
    
    private lazy var lineView: UIView = {
        let view = UIView(color: kRGBColor(239, 239, 239))
        return view
    }()
    
}

// MARK: - Public
extension YBCloudComputerBasicFuncCell {
    
    func updateCell(by type: YBCloudComputerDetailVC.SectionType.BasicFunc) {
        imgView.image = UIImage(named: type.style.icon)
        kTitleLabel.text = type.style.title
        desLabel.text = type.style.des
        lineView.isHidden = type == .pointConversion
    }
    
}
